package top.huxy.boot.controller.publicly;

import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import top.huxy.boot.model.dto.Pager;
import top.huxy.boot.model.vo.user.VO_Article;
import top.huxy.boot.service.ArticleService;
import top.huxy.boot.util.obj.Result;

import java.util.List;


/**
 * @author HuXY
 * @since 2021-12-21 09:59:01
 */
@RestController
@RequestMapping("/article")
public class ArticleController {
    @Autowired
    private ArticleService articleService;

    @GetMapping("/getArticleList")
    public Result getArticleList(Pager pager, @RequestParam(value = "type", defaultValue = "博客") String type) {
        List<VO_Article> list = articleService.getArticleList(pager, type);
        PageInfo<VO_Article> res = new PageInfo<>(list);
        return Result.success(res);
    }

    @GetMapping("/getArticleById")
    public Result getArticleById(@RequestParam(value = "id")Integer id) {
        VO_Article article = articleService.getArticleById(id);
        return Result.success(article);
    }
}
